package com.controller;

import com.pojo.Job;
import com.pojo.Page;
import com.service.JobService;
import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.List;

@Controller
@RequestMapping("/job")
public class JobController {
    @Resource
    private JobService service;
    /*查询职位*//*
    List<Job> queryAll(@Param("pageIndex") int pageIndex, @Param("pageSize") int pageSize);
    *//*添加职位*//*
    int addJob(Job job);
    *//*删除职位*//*
    int deleteJob(@Param("id") int id);
    *//*修改职位信息*//*
    int updateJob(Job job);
    *//*根据ID查询职位*//*
    Job queryById(@Param("id") int id);
    *//*根据职位名称查询职位*//*
    List<Job> queryByName(@Param("pageIndex") int pageIndex,@Param("pageSize") int pageSize,@Param("name") String name);*/
    @RequestMapping("queryAll")
    @ResponseBody
    public Page queryAll(int pageindex){
        Page page = new Page(5,pageindex);
        List<Job> list = service.queryAll(page.getStartIndex(),page.getEndIndex());
        int count = service.countAll(null);
        page.setResult(list,count);
        return page;
    }
    @RequestMapping("/addJob")
    @ResponseBody
    public String addJob(@RequestBody Job job){
        int result = service.addJob(job);
        if(result>0){
            return "{\"fig\":\"success\"}";
        }
        else{
            return "{\"fig\":\"error\"}";
        }
    }
    @RequestMapping("/deleteJob")
    @ResponseBody
    public String deleteJob(int id){
        int result = service.deleteJob(id);
        if(result>0){
            return "{\"fig\":\"success\"}";
        }
        else{
            return "{\"fig\":\"error\"}";
        }
    }
    @RequestMapping("/updateJob")
    @ResponseBody
    public String updateJob(@RequestBody Job job){
        int result = service.updateJob(job);
        if(result>0){
            return "{\"fig\":\"success\"}";
        }
        else{
            return "{\"fig\":\"error\"}";
        }
    }
    @RequestMapping("/queryById")
    @ResponseBody
    public Job queryById(int id){
        Job job = service.queryById(id);
        return job;
    }
    @RequestMapping("/queryByName")
    @ResponseBody
    public Page queryByName(int pageindex,String name){
        Page page = new Page(5,pageindex);
        List<Job> list = service.queryByName(page.getStartIndex(),page.getEndIndex(),name);
        int count = service.countAll(name);
        page.setResult(list,count);
        return page;
    }
}
